package org.ndx.jsg.config;

import java.io.File;
import java.util.Arrays;
import java.util.Collection;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.plist.PropertyListConfiguration;
import org.ndx.jsg.MimeTypes;
import org.ndx.jsg.input.FileInfosProviderModule;
import org.ndx.jsg.output.OutputManagerModule;

public class DefaultConfiguration {

	/**
	 * Property added only at runtime containing configuration file object
	 */
	public static final String CONFIGURATION_FILE = "configuration.file";
	/**
	 * Configuration used for mime types that will be directly copied from source to dest. 
	 */
	public static final String COPY_INCLUDE_MIME = "copy.include.mimeTypes";
	/**
	 * Get the list of ignored file names
	 */
	public static final String INPUT_IGNORED_NAMES = "input.ignored.names";
	public static final String INPUT_PATHS = "input.files";

	/**
	 * Configuration for directories templates
	 */
	public static final String JSG_TEMPLATES_DIRECTORIES = "jsg.templates.directories";

	/**
	 * Template directory for jsg xml processing
	 */
	public static final String JSG_TEMPLATES_DIRECTORY = "jsg.templates.directory";

	/**
	 * Configuration for global templates
	 */
	public static final String JSG_TEMPLATES_GLOBAL = "jsg.templates.global";

	public static final String MODULES_LIST = "modules.list";

	public static final String OUTPUT_PATH = "output.files";

	/**
	 * Creates the default configuration
	 * @return
	 */
	public static Configuration create() {
		PropertyListConfiguration returned = new PropertyListConfiguration();
		returned.setProperty(INPUT_PATHS, File.separator+"input");
		returned.setProperty(OUTPUT_PATH, File.separator+"output");
		
		returned.setProperty(INPUT_IGNORED_NAMES, getDefaultIgnoredNames());

		returned.setProperty(MODULES_LIST, getDefaultModules());
		
		returned.setProperty(DefaultConfiguration.COPY_INCLUDE_MIME, getDefaultCopiedMimeTypes());
		return returned;
	}

	private static Collection<String> getDefaultCopiedMimeTypes() {
		return Arrays.asList(MimeTypes.IMAGE_GIF, MimeTypes.IMAGE_JPEG, MimeTypes.IMAGE_PNG);
	}
	private static Object getDefaultIgnoredNames() {
		return Arrays.asList(".svn", ".cvs");
	}
	private static Collection<String> getDefaultModules() {
		return Arrays.asList(FileInfosProviderModule.class.getName(), OutputManagerModule.class.getName());
	}

}
